<?php
namespace Home\Controller;
use Think\Controller;

/**
 * 教务数据
 * Date: 2018/8/17
 * Time: 16:03
 * Class EducationDataController
 * @package Home\Controller
 */
class EducationDataController extends Controller
{
    public function _initialize()
    {

    }

    /**
     * 学员异动
     */
    public function studentAbnormalChanges()
    {
        //年份
        $dateList = $this->getAllDate();

        //校区
        $schoolList = $this->getAllSchool();


        $this->assign('dateList', $dateList);
        $this->assign('schoolList', $schoolList);
        $this->display();
    }

    /**
     * TODO 新增比
     */
    public function newAddPercentage()
    {
        $this->display();
    }

    /**
     * TODO 教师课量分析
     */
    public function teacherClassNum()
    {
        $this->display();
    }

    /**
     * TODO 续报比
     */
    public function renewPercentage()
    {
        $this->display();
    }

    /**
     * 获取所有校区
     * @return array 校区数组
     */
    public function getAllSchool()
    {
        $schoolList = M('student_abnormal_changes_analysis_log')->distinct(true)->field('school_area_id,school_area_name')->select();

        return $schoolList;
    }


    /**
     * 获取所有年份
     * @return array 年份数组
     */
    public function getAllDate()
    {
        $dateList = [];

        for($i = 2017; $i<= 2018; $i++)
        {
            array_push($dateList, ['year' => $i]);
        }

        return $dateList;
    }

    /**
     * 查询学员异动（转班、休学）数据
     * @return array 异动数组
     */
    public function getStudentChanges()
    {

        $where = array();
        $where['year'] = I('get.date', 2018);
        $where['school_area_id'] = I('get.school', 1);

        $studentChangesList = M('student_abnormal_changes_analysis_log')
            ->field('type, month, num')
            ->where($where)
            ->order('month asc')
            ->select();

        $result = array();
        foreach ($studentChangesList as $item => $value)
        {
            if ($value['type'] == '转班') {
                $result['transfer_class'][$value['month']] = $value['num'];
            } else {
                $result['temp_leave_student'][$value['month']] = $value['num'];
            }
        }

        $return['err_code'] = 0;
        $return['result'] = $result;

        $this->ajaxReturn($return);

    }
}